<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%--
  Created by IntelliJ IDEA.
  User: wagger
  Date: 2019/06/02
  Time: 下午 11:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>Traveler Blog -->文章管理</title>
    <link rel="stylesheet" type="text/css" href="/client/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/client/css/main.css"/>
    <link href="/client/css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <link href="/client/css/style.css" type="text/css" rel="stylesheet">
    <link type="text/css" href="/client/css/nprogress.css" rel="stylesheet">
    <link rel="shortcut icon" href="/client/images/tou.ico">
</head>
<body>
<jsp:include page="/client/head.jsp"/>
<div class="main-wrap">
    <div class="search-wrap">
        <div class="search-content">
            <form action="/admin/search.do" id="myform" method="post">
                <table class="search-tab">
                    <tr>
                        <th width="120">选择分类:</th>
                        <td>
                            <select name="ptags">
                                <option selected="selected" name="ptags" >--选择类别--</option>
                                <c:forEach items="${search}" var="search">
                                    <option value="${search.tags}">${search.tags}</option>
                                </c:forEach>
                            </select>
                        </td>
                        <th width="70">关键字:</th>
                        <td><input class="common-text" placeholder="关键字" name="ptitle"type="text"/></td>
                        <td><input class="btn btn-primary btn2" name="sub" value="查询" type="button" onclick="search()"/></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div class="result-wrap">
        <form name="myform"  method="post">
            <div class="result-title">
                <div class="result-list">
                    <a href="/admin/addUI.do">新增作品</a>
                </div>
            </div>
            <div class="result-content">
                <table class="result-tab" width="100%">
                    <tr>
                        <th>ID</th>
                        <th>标题</th>
                        <th>内容</th>
                        <th>Img</th>
                        <th>分类</th>
                        <th>浏览量</th>
                        <th>发布人</th>
                        <th>发布时间</th>
                        <th>评论量</th>
                        <th>操作</th>
                    </tr>
                    <tbody id="showPorducts">
                    <c:forEach items="${artileList}" var="al">
                    <tr >
                        <td>${al.pid}</td>
                        <td title="${al.title}">${al.title}</td>
                        <td style="overflow: hidden;height: 32px;width: 20%">${al.page}</td>
                        <td><img src="${al.img}" style="height: 200px;width: 250px"/></td>
                        <td>${al.tags}</td>
                        <td>${al.click}</td>
                        <td>${al.author}</td>
                        <td><fmt:formatDate value="${al.time}" pattern="yyyy-MM-dd"/></td>
                        <td>${al.comment}</td>
                        <td>
                            <a class="link-update" href="${pageContext.request.contextPath}/admin/findById.do?aid=${al.pid}">修改</a>
                            <a class="link-del" href="${pageContext.request.contextPath}/admin/deleteById.do?aid=${al.pid}">删除</a>
                        </td>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </form>
    </div>
</div>
</body>
<script src="/client/js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script type="application/javascript">
    function search() {
        var formDate = $("#myform").serialize();

        $.ajax({
            url:"/admin/search.do",
            type:"post",
            data:formDate,
            dataType:"json",

            success:function (data) {
                var str1 = "";
                /*原内容清空*/
                $("#showPorducts").html("");
                for (var i = 0; i < data.length; i++) {
                    var str1 = "<tr >"+
                    "                        <td>"+ data[i].pid +"</td>"+
                    "                        <td>"+ data[i].title +"</td>"+
                    "                        <td style=\"overflow: hidden;height: 32px;width: 20%\">"+ data[i].page +"</td>"+
                    "                        <td><img src=\""+ data[i].img +"\" style=\"height: 200px;width: 250px\"/></td>"+
                    "                        <td>"+ data[i].tags +"</td>"+
                    "                        <td>"+ data[i].click +"</td>"+
                    "                        <td>"+ data[i].author +"</td>"+
                    "                        <td>"+ getLocalTime(data[i].time) +"</td>"+
                    "                        <td>"+ data[i].comment +"</td>"+
                    "                        <td>"+
                    "                            <a class=\"link-update\" href=\"${pageContext.request.contextPath}/admin/findById.do?aid="+ data[i].pid +"\">修改</a>"+
                    "                            <a class=\"link-del\" href=\"${pageContext.request.contextPath}/admin/deleteById.do?aid="+ data[i].pid +"\">删除</a>"+
                    "                        </td>"+
                    "                    </tr>";
                    $("#showPorducts").append(str1);

                }
            }
        })
    }
</script>
<script type="application/javascript">
    function getLocalTime(nS) {
        //将时间戳（十三位时间搓，也就是带毫秒的时间搓）转换成时间格式
        // d.cTime = 1539083829787
        let date = new Date(nS);
        let year = date.getFullYear();
        let month = date.getMonth()+1;
        let day = date.getDate();
        month = month < 10 ? "0"+month:month;
        day = day < 10 ? "0"+day:day;
        date = year+'-'+month+'-'+day;
        console.log(date); // 2018-10-09
        return date;
    }
</script>
</html>
